package com.gzrhhscd.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static final String signKey="gzrhhscd";
    private static final long  expire=43200000L;

public static String generateJwt(Map<String,Object>claims){
    String jwt= Jwts.builder()
            .setClaims(claims)//自定义内容，载荷
            .signWith(SignatureAlgorithm.HS256,signKey)  //签名算法
            .setExpiration(new Date(System.currentTimeMillis()+expire))//有效期
            .compact();
    return jwt;
}
    public static Claims parseJwt(String jwt){
        Claims claims=Jwts.parser()
                .setSigningKey(signKey)//指定签名秘钥
                .parseClaimsJws(jwt)//解析令牌
                .getBody();
       return claims;
    }


}
